package com.demo.customer;

import com.demo.common.model.Customer;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

/**
 * BlogController
 * 所有 sql 与业务逻辑写在 Model 或 Service 中，不要写在 Controller 中，养成好习惯，有利于大型项目的开发与维护
 */
@Before(CustomerInterceptor.class)
public class CustomerController extends Controller {
	public void index() {
		setAttr("blogPage", Customer.me.paginate(getParaToInt(0, 1), 20));
		render("blog.html");
	}
	public void showGet() {
		setAttr("blogPage", Customer.me.paginateGet(getParaToInt(0, 1), 20));
		render("blog.html");
	}
	public void showGetOne() {
		String code = getPara("code").trim();
		setAttr("blogPage", Customer.me.paginateOne(getParaToInt(0, 1), 10,code));
		render("blog.html");
	}
	
	public void add() {
	}
	
	@Before(CustomerValidator.class)
	public void save() {
		getModel(Customer.class).save();
		redirect("/custome");
	}
	
	public void edit() {
		setAttr("blog", Customer.me.findById(getParaToInt()));
	}
	
	@Before(CustomerValidator.class)
	public void update() {
		getModel(Customer.class).update();
		redirect("/custome");
	}
	
	public void delete() {
		Customer.me.deleteById(getParaToInt());
		redirect("/custome");
	}
	
	public void get() {
		int id = getParaToInt(0);
		Customer sel = Customer.me.findById(id);
		if(sel!=null){
			sel.set("is_get", 1).update();
		}
		//Customer.me.deleteById(getParaToInt());
		redirect("/custome");
	}
}


